import {request} from "@/network/request";

// 创建定单
export function createOrder(params:{address_id:string}) {
    return request({
        url: "/api/orders",
        method: "post",
        params,
    });
}

// 获取定单预览
export function getOrderPreview() {
    return request({
        url: "/api/orders/preview",
    });
}

// 定单支付, 获取二维
export function payOrder(orderId:string, params:{type:string}) {
    return request({
        url: `/api/orders/${orderId}/pay`,
        params,
    });
}

// 定单状态
export function payOrderStatus(orderId:string) {
    return request({
        url: `/api/orders/${orderId}/status`,
    });
}

// 获取定单列表 {page:1, status:2, include:'user,orderDetail.goods'}
export function getOrderList(params:{page:number, status:number, include:string}) {
    return request({
        url: "/api/orders",
        params,
    });
}

// 定单详情
export function getOrderDetail(orderId:string) {
    return request({
        url: `/api/orders/${orderId}`,
        params: {
            include: "user,orderDetails.goods",
        },
    });
}

// 确认定单
export function confirmOrder(orderId:string) {
    return request({
        url: `/api/orders/${orderId}/confirm`,
        method: "patch",
    });
}

// 获取物流信息 /api/orders/{order}/express
export function viewExpress(orderId:string) {
    return request({
        url: `/api/orders/${orderId}/express`,
    });
}
